from django.db import models


# Create your models here.
# 关注粉丝用的user
class User(models.Model):
    name = models.CharField(max_length=120)
    age = models.IntegerField()


# 关注粉丝用的闭包
class Follow(models.Model):
    idol = models.ForeignKey(User, on_delete=models.CASCADE, related_name='idol')
    fans = models.ForeignKey(User, on_delete=models.CASCADE, related_name='fans')

    def __str__(self):
        return '%s关注了%s' % (self.fans.name, self.idol.name)


'''
In [1]: from apapapap.models import *
In [4]: u1=User.objects.create(name='张三',age=18)
In [5]: u2=User.objects.create(name='李四',age=18)
In [6]: u3=User.objects.create(name='王五',age=18)
In [12]: u4=User.objects.create(name='马六',age=18)
In [13]: u5=User.objects.create(name='孙七',age=18)
In[17]Follow.objects.create(idol=u3,fans=u4)
Out[17]: <Follow: 马六关注了王五>

'''


# User.objects.filter(idol__fans__name__contains='李四')
# User.objects.filter(fans__idos__name__contains='李四')


# 评论用的user
class pinguser(models.Model):
    name = models.CharField(max_length=200)


# 无限极评论的model
class pinglunmodel(models.Model):
    user = models.ForeignKey(pinguser, models.CASCADE)
    content = models.CharField(max_length=255)
    pid = models.IntegerField(default=0)


# 筛选usermodel
class yonghushaixuan(models.Model):
    gender = models.CharField(max_length=30)
    age = models.IntegerField()
    payment = models.FloatField()
    city = models.CharField(max_length=300, null=True)


# 生成验证码
class yanzhengmamodel(models.Model):
    username = models.CharField(max_length=120)
